package cz.najman.emdroid.helper;

import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
import cz.najman.emdroid.connection.ConnectionMethod;
import cz.najman.emdroid.mappings.Event;
import cz.najman.emdroid.mappings.PaymentInformation;
import cz.najman.emdroid.mappings.PaymentValue;
import cz.najman.emdroid.mappings.StornoValue;
import cz.najman.emdroid.service.ForwardingResultReceiver;
import cz.najman.emdroid.service.UpdaterService;

public class PaymentInformationHelper extends AbstractHelper {
	private static final String TAG = "PaymentInformationHelper";
	
	public PaymentInformationHelper(Context context, ForwardingResultReceiver receiver) {
		super(context, receiver);		
	}
	
	/* ***************************************************************
	 * 					REMOTE HELPER METHODS 						 *
	 * ***************************************************************/
	
	public void retrieveEventPaymentValues(int eventId){
		Log.d(TAG, "> retrirvrEventPaymentValues");
		Intent intent = getIntentWithExtra(
				PaymentValue.CONTENT_URI_PAYMENT_VALUES,
				ConnectionMethod.METHOD_GET,
				new String[] {Event.URI_TEMPLATE_STRING},
				new String[] {"" + eventId},
				null
			);        
        mContext.startService(intent);
	}
	
	public void retrieveEventStornoValues(int eventId){
		Log.d(TAG, "> retrieveEventPaymentValues");
		Intent intent = getIntentWithExtra(
				StornoValue.CONTENT_URI_STORNO_VALUES,
				ConnectionMethod.METHOD_GET,
				new String[] {Event.URI_TEMPLATE_STRING},
				new String[] {"" + eventId},
				null
			);        
        mContext.startService(intent);
	}
	
	@Override
	protected Intent getIntentWithExtra(Uri uri, int method, String[] parameterTypes, String[] parameterValues, ContentValues values) {
		Intent intent = new Intent(mContext, UpdaterService.class);
		intent.putExtra(UpdaterService.RESULT_RECEIVER,	mResultReceiver);
		intent.putExtra(UpdaterService.OBJECT, PaymentInformation.class);
		intent.putExtra(UpdaterService.URI, uri);
		intent.putExtra(UpdaterService.METHOD, method);
		if (parameterTypes != null) {
			intent.putExtra(UpdaterService.PARAMETER_TYPES, parameterTypes);
			intent.putExtra(UpdaterService.PARAMETER_VALUES, parameterValues);
		}
		if (values != null) {
			intent.putExtra(UpdaterService.CONTENT_VALUES, values);
		}

		return intent;
	}
	
	/* ***************************************************************
	 * 					DATABASE HELPER METHODS 					 *
	 * ***************************************************************/
	//TODO
	public Cursor getPaymentValues(String[] projection, String selection, String sortOrder){
		return mContentResolver.query(PaymentValue.CONTENT_URI_PAYMENT_VALUES, projection, selection, null, sortOrder);
	}
	
	public Cursor getStornoValues(String[] projection, String selection, String sortOrder){
		return mContentResolver.query(StornoValue.CONTENT_URI_STORNO_VALUES, projection, selection, null, sortOrder);
	}

}
